package com.hy.main.demo.stream;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author yang DongYong
 * @Date 2022/6/22 - 06 - 22 - 21:06
 * @Description: com.hy.main.demo.stream
 * @version: 1.0
 */
public class StreamDemo {
    //测试方法
    @Test
    public void test01(){
        List<Student> students = Arrays.asList(new Student("张三", 20, "男"),
                new Student("李四", 25, "男"),
                new Student("王五", 30, "女"));
        Map<Boolean, List<Student>> collect = students.stream().collect(Collectors.partitioningBy(stu -> stu.getSex() == "女"));
        System.out.println(collect.get(false));
    }

    //测试方法
    @Test
    public void test02(){
        List<Student> students = Arrays.asList(new Student("张三", 20, "男"),
                new Student("李四", 25, "男"),
                new Student("王五", 30, "女"));


        List<Person> collect = students.stream().map(student -> {
            return Person.builder().name(student.getName()).build();
        }).collect(Collectors.toList());
        System.out.println(collect.toString());

    }

}
